import heapq

def read_input(file_name):
    with open(file_name, 'r') as file:
        lines = file.readlines()
        k = int(lines[0].strip())
        lengths = list(map(int, lines[1].strip().split()))
    return k, lengths

def min_cost_merge(lengths):
    min_heap = [length for length in lengths]
    heapq.heapify(min_heap)
    total_cost = 0
    
    while len(min_heap) > 1:
        first = heapq.heappop(min_heap)
        second = heapq.heappop(min_heap)
        merged = first + second
        heapq.heappush(min_heap, merged)
        total_cost += merged - 2  # Each merge costs merged - 2 comparisons
    
    return total_cost - len(lengths) + 1  # Subtract k-1 because we over-counted by k-1

def max_cost_merge(lengths):
    max_heap = [-length for length in lengths]
    heapq.heapify(max_heap)
    total_cost = 0
    
    while len(max_heap) > 1:
        first = -heapq.heappop(max_heap)
        second = -heapq.heappop(max_heap)
        merged = first + second
        heapq.heappush(max_heap, -merged)
        total_cost += merged - 2  # Each merge costs merged - 2 comparisons
    
    return total_cost - len(lengths) + 1  # Subtract k-1 because we over-counted by k-1

def write_output(file_name, min_cost, max_cost):
    with open(file_name, 'w') as file:
        file.write(f"{min_cost} {max_cost}\n")

def main():
    input_file = 'input.txt'
    output_file = 'output.txt'
    
    k, lengths = read_input(input_file)
    
    min_cost = min_cost_merge(lengths)
    max_cost = max_cost_merge(lengths)
    
    write_output(output_file, min_cost, max_cost)

if __name__ == "__main__":
    main()
